package com.scau.RBAC.util;

import javax.sql.DataSource;
import org.apache.commons.dbcp2.BasicDataSource;

/**
 * 数据库连接池工具类
 */
public class DBConnectionPool {
    private static DataSource dataSource;

    static {
        BasicDataSource ds = new BasicDataSource();
        ds.setDriverClassName(DBConfig.getProperty("spring.datasource.driver-class-name"));
        ds.setUrl(DBConfig.getProperty("spring.datasource.url"));
        ds.setUsername(DBConfig.getProperty("spring.datasource.username"));
        ds.setPassword(DBConfig.getProperty("spring.datasource.password"));

        // 连接池配置
        ds.setInitialSize(5);
        ds.setMaxTotal(20);
        ds.setMinIdle(5);
        ds.setMaxIdle(10);
        ds.setMaxWaitMillis(10000);

        dataSource = ds;
    }

    public static DataSource getDataSource() {
        return dataSource;
    }
}
